﻿#include <iostream>
#include <fstream>
#include <sstream>
#include <boost/algorithm/string.hpp>
#include <io.h>
#include<Windows.h>
#include <direct.h>
#include <BaseCommon.h>
#include "swi_calculate.h"

using namespace std;
using namespace JGG;

SwiCalculate::SwiCalculate(std::string swi_filename, std::string dat_filename)
{
}

SwiCalculate::~SwiCalculate()
{
}

int SwiCalculate::LineFaultCreate(const std::vector <std::string>& ZoneName, double volmin, double volmax)
{
    inst = new BPA::BPAFilesIO::GetDatFromDb(datParser, database, CaseIDTmp);

    //数据库中生成所有故障；用户指定故障范围,故障类型,故障开始、结束时间,作为参数传递

    BUSVector BusList = inst->GetBusList();

    LINEVector DCLineList = inst->GetLineLDList();
    int nDCLine = DCLineList.size();
    //模拟直流线路故障,包含单极闭锁,双极闭锁
    //建立一个直流线路表,BDName1,BDVol1,BDName2,BDVol2,ConvertName1,Qshunt1,ConvertName2,Qshunt2

    //模拟交流线路故障,不考虑小开关支路,这里考虑N-1,N-2,三相短路

    SqliteHelperDataBase db;
    SqliteHelperBuffer bufSQL;
    db.open(database);

    VerifyTable(&db);

    db.beginTransaction();
    //主要是处理三相N-1和三相N-2的交流线路
    //线路三相故障(N-2),有平行标志的线路
    for (int i = 0; i < ZoneName.size(); i++)
    {
        bufSQL.format("insert into N_1ACLineList select a.[CaseID],a.[LineID],a.[StartName],a.[StartVol],a.[EndName],a.[EndVol],d.[ShuntFlag] from LineList a,buslist b,Zonelist c,LineNormalList d where (a.[StartNum] = b.[BusID])and (a.[CardType] = 'L ')and(a.[LineID] = d.[LineID]) and b.[BusZoneID] = c.[ZoneID] and c.[ZoneName_EN] = (%Q) and (b.[BusVol] >=(%f) and b.[BusVol] <=(%f) )and (a.[CaseID] = %d) group by a.[StartNum],a.[EndNum] having count(*)>=1;",
            ZoneName[i].c_str(), volmin, volmax, CaseIDTmp);
        db.execDML(bufSQL);

        bufSQL.format("insert into N_2ACLineList select a.[CaseID],a.[LineID],a.[StartName],a.[StartVol],a.[EndName],a.[EndVol] ,d.[ShuntFlag] from LineList a,buslist b,Zonelist c,LineNormalList d  where (a.[StartNum] = b.[BusID])and (a.[CardType] = 'L ') and (a.[LineID] = d.[LineID])and  b.[BusZoneID] = c.[ZoneID] and c.[ZoneName_EN] = (%Q) and (b.[BusVol] >=(%f) and b.[BusVol] <=(%f) )and (a.[CaseID] = %d) group by a.[StartNum],a.[EndNum] having count(*)=2;",
            ZoneName[i].c_str(), volmin, volmin, CaseIDTmp);
        db.execDML(bufSQL);
    }

    //模拟直流单极闭锁（对于一条直流线路：LS直流故障卡+LS且负荷卡）
    //对于直流线路模拟单极闭锁
    for (int i = 0; i < nDCLine; i++)
    {
        LINE templine = DCLineList[i];
        BUS start = BusList[templine.StartNum - 1];
        BUS end = BusList[templine.EndNum - 1];

        stringstream oss;
        oss.str("");
        oss << "insert into DCLineSingleLockList (CaseID, id, BDName1, BDVol1, "
            << "BDName2, BDVol2, ConvertBusID, ConvertName1, ConvertVolBase1, "
            << "Qshunt1, ConvertName2, ConvertVolBase2, Qshunt2) values ("
            << CaseIDTmp << ", " << i + 1 << ", '" << templine.LineStart.c_str() << "', "
            << templine.StartVol << ", '" << templine.LineEnd.c_str() << "', "
            << templine.EndVol << ", " << start.ConvertBusID << ", '"
            << start.Name_Convert.c_str() << "', " << start.VolBase_Convert << ", "
            << BusList[start.ConvertBusID - 1].Qshunt << ", '" << end.Name_Convert.c_str() << "', "
            << end.VolBase_Convert << ", " << BusList[end.ConvertBusID - 1].Qshunt << ");";
        db.execDML(oss.str().c_str());
    }

    //对于直流线路模拟双极闭锁
    int ConvertID1, ConvertID2;		//以换流站节点编号的差异作为单双极的标志fabs(ConvertID1 - ConvertID2) <= 2;
    for (int i = 0; i < nDCLine - 1; i++)
    {
        ConvertID1 = BusList[DCLineList[i].StartNum - 1].ConvertBusID;
        ConvertID2 = BusList[DCLineList[i + 1].StartNum - 1].ConvertBusID;

        if (abs(ConvertID1 - ConvertID2) <= 2)
        {
            char buf11[700];
            sprintf_s(buf11, "insert into DCLineDoubleLockList (CaseID,id,LD1BDName1,LD1BDVol1,LD1BDName2,LD1BDVol2,LD1ConvertName1,LD1ConvertVolBase1,LD1Qshunt1,LD1ConvertName2,LD1ConvertVolBase2,LD1Qshunt2,LD2BDName1,LD2BDVol1,LD2BDName2,LD2BDVol2,LD2ConvertName1,LD2ConvertVolBase1,LD2Qshunt1,LD2ConvertName2,LD2ConvertVolBase2,LD2Qshunt2) values (%d,%d,'%s',%f,'%s',%f,'%s',%f,%f,'%s',%f,%f,'%s',%f,'%s',%f,'%s',%f,%f,'%s',%f,%f);",
                CaseIDTmp, i + 1, DCLineList[i].LineStart.c_str(), DCLineList[i].StartVol, DCLineList[i].LineEnd.c_str(), DCLineList[i].EndVol,
                BusList[DCLineList[i].StartNum - 1].Name_Convert.c_str(), BusList[DCLineList[i].StartNum - 1].VolBase_Convert, BusList[BusList[DCLineList[i].StartNum - 1].ConvertBusID - 1].Qshunt,
                BusList[DCLineList[i].EndNum - 1].Name_Convert.c_str(), BusList[DCLineList[i].EndNum - 1].VolBase_Convert, BusList[BusList[DCLineList[i].EndNum - 1].ConvertBusID - 1].Qshunt,

                DCLineList[i + 1].LineStart.c_str(), DCLineList[i + 1].StartVol, DCLineList[i + 1].LineEnd.c_str(), DCLineList[i + 1].EndVol,
                BusList[DCLineList[i + 1].StartNum - 1].Name_Convert.c_str(), BusList[DCLineList[i + 1].StartNum - 1].VolBase_Convert, BusList[BusList[DCLineList[+1].StartNum - 1].ConvertBusID - 1].Qshunt,
                BusList[DCLineList[i + 1].EndNum - 1].Name_Convert.c_str(), BusList[DCLineList[i + 1].EndNum - 1].VolBase_Convert, BusList[BusList[DCLineList[i + 1].EndNum - 1].ConvertBusID - 1].Qshunt);


            db.execDML(buf11);
        }
    }
    char buf6[200];
    sprintf_s(buf6, "update DCLineSingleLockList set  Qshunt1 = 0 where Qshunt1 = 999999");				//值未填情况的恢复
    db.execDML(buf6);
    sprintf_s(buf6, "update DCLineSingleLockList set  Qshunt2 = 0 where Qshunt2 = 999999");				//值未填情况的恢复
    db.execDML(buf6);
    db.commitTransaction();
    db.close();

    return true;

}

int SwiCalculate::Calculate(const SwiBatchParameter& Batchpara)
{
    if (ToExecuteSwi::GetBreakCycle())
    {
    	return true;
    }

    string tempDir = "./bpa_temp/swi_multi_calculate/temp.swi";
    BPA_SFM_DataBaseToSWIFile(SwiCaseID, tempDir.c_str(), database);

    // get base file name
    std::vector <std::string> files =
        filesystem::CPath::has_extension(".\\bpa_temp\\swi_multi_calculate", "BSE", false);
    std::string baseFileName = files[0];

    BPA::BPAFilesIO::BpaSwi bpaSwi;
    bpaSwi.ReadSwi(tempDir.c_str());

    SqliteHelperDataBase db;
    SqliteHelperBuffer bufSQL;
    db.open(database);

    bufSQL.format(" select * from N_1ACLineList where CaseID = (%d);",DatCaseID );		//筛出普通母线信息
    SqliteHelperTable Table_N_1ACLineList = db.getTable(bufSQL);
    int ACN_1Num = Table_N_1ACLineList.numRows();

    bufSQL.format(" select * from N_2ACLineList where CaseID = (%d);",DatCaseID );		//筛出普通母线信息
    SqliteHelperTable Table_N_2ACLineList = db.getTable(bufSQL);
    int ACN_2Num = Table_N_2ACLineList.numRows();

    //模拟直流线路故障，包含单极闭锁
    bufSQL.format(" select * from DCLineSingleLockList where CaseID = (%d);",DatCaseID );		//筛出普通母线信息
    SqliteHelperTable Table_DCLineSingleLockList = db.getTable(bufSQL);
    int DCSingleNum = Table_DCLineSingleLockList.numRows();

    //模拟直流线路故障，包含双极闭锁
    bufSQL.format(" select * from DCLineDoubleLockList where CaseID = (%d);",DatCaseID );		//筛出普通母线信息
    SqliteHelperTable Table_DCLineDoubleLockList = db.getTable(bufSQL);
    int DCDoubleNum = Table_DCLineDoubleLockList.numRows();

    string SwiBusName1,SwiBusName2;

    //模拟故障选择FaultFlag变量，31：三相N-1，32：三相N-2；11：直流单极闭锁；12：直流双极闭锁
    //p.SwiWriteBackToMulti(FileNameCal,LSStartTmp,LSEndTmp,三相N-2传参；直流单极传参；直流双极传参)

    ThreeShort_LineBreak LSStartTmp;		//故障开始 三相故障 N-1，N-2
    ThreeShort_LineBreak LSEndTmp;			//故障结束
    FLT FLTmp;								//简化故障形式

    Fault_DtoD1 LDSingleBreakTmp;					//直流单极
    GenTrip_LoadShed LoadSingleCutTmp1,LoadSingleCutTmp2;			//切机、切负荷

    Fault_DtoD1 LDDoubleBreakTmp1,LDDoubleBreakTmp2;					//直流双极
    GenTrip_LoadShed LoadDoubleCutTmp1,LoadDoubleCutTmp2,LoadDoubleCutTmp3,LoadDoubleCutTmp4;			//切机、切负荷

    int AcAndDC = 0;
    switch (Batchpara.ACFaultType)
    {
    case 31:		//三相N-1
    	{
    		for(int i =0;i<ACN_1Num;i++)
    		{
    			if (ToExecuteSwi::GetBreakCycle())
    			{
    				break;
    			}
    			Table_N_1ACLineList.setRow(i);
    			//故障开始
    			SwiBusName1 = Table_N_1ACLineList.getStringField(2);
    			SwiBusName2 = Table_N_1ACLineList.getStringField(4);
    			boost::replace_all(SwiBusName1,"$","'");
    			boost::replace_all(SwiBusName1,"$","'");
    			LSStartTmp.FaultFlg = "LS";
    			LSStartTmp.Sign_A = " ";
    			LSStartTmp.Bus_A = SwiBusName1;
    			LSStartTmp.BaseVol_A = Table_N_1ACLineList.getFloatField(3);
    			LSStartTmp.Sign_B = " ";
    			LSStartTmp.Bus_B = SwiBusName2;
    			LSStartTmp.BaseVol_B = Table_N_1ACLineList.getFloatField(5);
    			LSStartTmp.ParNum = Table_N_1ACLineList.getStringField(6);
    			//LSStartTmp.ParNum = "1";

    			
    			LSStartTmp.Mde = 1;
    			//LSStartTmp.Cycle = StartTime;
    			LSStartTmp.Cycle = Batchpara.ACFaultBegin;

    			//故障跳开
    			LSEndTmp.FaultFlg = "LS";
    			LSEndTmp.Sign_A = "-";
    			LSEndTmp.Bus_A = SwiBusName1;
    			LSEndTmp.BaseVol_A = Table_N_1ACLineList.getFloatField(3);
    			LSEndTmp.Sign_B = "-";
    			LSEndTmp.Bus_B = SwiBusName2;
    			LSEndTmp.BaseVol_B = Table_N_1ACLineList.getFloatField(5);
    			LSEndTmp.ParNum = Table_N_1ACLineList.getStringField(6);
    			LSEndTmp.Mde = 1;
    			//LSEndTmp.Cycle  = EndTime;
    			LSEndTmp.Cycle  = Batchpara.ACFaultEnd;
    			AcAndDC = i+1;
    			//考虑带至行文件名参数
                stringstream fileNameCalculate("");
                fileNameCalculate << ".\\bpa_temp\\swi_multi_calculate\\temp_" << AcAndDC << ".swi";
    			//将这两个结构体传递给文件并且指定计算的文件名
    			bpaSwi.SwiWriteBackToMulti(
                    fileNameCalculate.str(),
                    31,
                    LSStartTmp,
                    LSEndTmp,
                    FLTmp,
                    LDSingleBreakTmp,
                    LoadSingleCutTmp1,
                    LoadSingleCutTmp2,
    				LDDoubleBreakTmp1,
                    LDDoubleBreakTmp2,
                    LoadDoubleCutTmp1,
                    LoadDoubleCutTmp2,
                    LoadDoubleCutTmp3,
                    LoadDoubleCutTmp4);
                ExecuteSwi(fileNameCalculate.str(), baseFileName);

    			}
    		}
    		break;
    case 32:		//三相N-2
    	{
    		for (int i = 0;i<ACN_2Num;i++)
    		{
    			if (ToExecuteSwi::GetBreakCycle())
    			{
    				break;
    			}
    			SwiBusName1 = Table_N_1ACLineList.getStringField(2);
    			SwiBusName2 = Table_N_1ACLineList.getStringField(4);
    			boost::replace_all(SwiBusName1,"$","'");
    			boost::replace_all(SwiBusName1,"$","'");
    			//简化故障卡
    			FLTmp.Cardtype = "FLT";
    			FLTmp.A = SwiBusName1;
    			FLTmp.BaseVol_A = Table_N_2ACLineList.getFloatField(3);
    			FLTmp.B = SwiBusName2;
    			FLTmp.BaseVol_B = Table_N_2ACLineList.getFloatField(5);
    			FLTmp.A = Table_N_2ACLineList.getStringField(2);
    			FLTmp.ID = "1";
    			FLTmp.FaultSide = 1;
    			FLTmp.FaultType = 1;

    			FLTmp.FaultTime = Batchpara.ACFaultBegin;
    			FLTmp.T1 = Batchpara.ACFrontCut;
    			FLTmp.T2 = Batchpara.ACBackCut;

    			//LS卡
    			LSEndTmp.FaultFlg = "LS";
    			LSEndTmp.Sign_A = "-";
    			LSEndTmp.Bus_A = SwiBusName1;
    			LSEndTmp.BaseVol_A = Table_N_1ACLineList.getFloatField(3);
    			LSEndTmp.Sign_B = "-";
    			LSEndTmp.Bus_B = SwiBusName2;
    			LSEndTmp.BaseVol_B = Table_N_1ACLineList.getFloatField(5);
    			LSEndTmp.ParNum = "2";
    			LSEndTmp.Mde = 1;
    			LSEndTmp.Cycle = Batchpara.ACBackCut;

    			//考虑带至行文件名参数
    			AcAndDC = i+1;
                stringstream fileNameCalculate("");
                fileNameCalculate << ".\\bpa_temp\\swi_multi_calculate\\temp_" << AcAndDC << ".swi";

    			//将这两个结构体传递给文件并且指定计算的文件名
                bpaSwi.SwiWriteBackToMulti(
                    fileNameCalculate.str(),
                    32,
                    LSStartTmp,
                    LSEndTmp,
                    FLTmp,
                    LDSingleBreakTmp,
                    LoadSingleCutTmp1,
                    LoadSingleCutTmp2,
    				LDDoubleBreakTmp1,
                    LDDoubleBreakTmp2,
                    LoadDoubleCutTmp1,
                    LoadDoubleCutTmp2,
                    LoadDoubleCutTmp3,
                    LoadDoubleCutTmp4);
                ExecuteSwi(fileNameCalculate.str(), baseFileName);
    		}
    		break;
    	}
    default:
    	break;
    }


    //模拟直流故障
    switch (Batchpara.DCFaultType)
    {
    case 11:		//直流单极
    	{
    		//Fault_DtoD1 LDSingleBreakTmp;					//直流故障
    		//GenTrip_LoadShed LoadSingleCutTmp1,LoadSingleCutTmp2;			//切机、切负荷
    		//double DCLineStartTime = 10;			//用户指参数
    		//double DCLoadCutTime = 15;				//用户指定参数
    		for (int i =0;i<DCSingleNum;i++)
    		{
    			if (ToExecuteSwi::GetBreakCycle())
    			{
    				break;
    			}
    			//模拟直流故障
    			LDSingleBreakTmp.FaultFlg = "LS";
    			SwiBusName1 = Table_DCLineSingleLockList.getStringField(2);
    			SwiBusName2 = Table_DCLineSingleLockList.getStringField(4);
    			boost::replace_all(SwiBusName1,"$","'");
    			boost::replace_all(SwiBusName1,"$","'");
    			LDSingleBreakTmp.Bus_A = SwiBusName1;
    			LDSingleBreakTmp.BaseVol_A = Table_DCLineSingleLockList.getFloatField(3);
    			LDSingleBreakTmp.Bus_B =SwiBusName2;
    			LDSingleBreakTmp.BaseVol_B = Table_DCLineSingleLockList.getFloatField(5);
    			LDSingleBreakTmp.Mde = 5;
    			LDSingleBreakTmp.FaultStyle_D = 4;
    			//LDSingleBreakTmp.Cycle = DCLineStartTime;
    			LDSingleBreakTmp.Cycle = Batchpara.DCFaultBegin;


    			//模拟切负荷
    			SwiBusName1 = Table_DCLineSingleLockList.getStringField(7);
    			SwiBusName2 = Table_DCLineSingleLockList.getStringField(10);
    			boost::replace_all(SwiBusName1,"$","'");
    			boost::replace_all(SwiBusName1,"$","'");
    			//补偿1
    			LoadSingleCutTmp1.FaultFlg = "LS";
    			LoadSingleCutTmp1.BusName =SwiBusName1;
    			LoadSingleCutTmp1.BusVol = Table_DCLineSingleLockList.getFloatField(8);
    			LoadSingleCutTmp1.Mde = 4;
    			//LoadSingleCutTmp1.Cycle = DCLoadCutTime;
    			LoadSingleCutTmp1.Cycle = Batchpara.DCCut;



    			LoadSingleCutTmp1.QZ = int(Table_DCLineSingleLockList.getFloatField(9)/2);
    			//补偿2
    			LoadSingleCutTmp2.FaultFlg = "LS";
    			LoadSingleCutTmp2.BusName =SwiBusName2;
    			LoadSingleCutTmp2.BusVol = Table_DCLineSingleLockList.getFloatField(11);
    			LoadSingleCutTmp2.Mde = 4;
    			//LoadSingleCutTmp2.Cycle = DCLoadCutTime;
    			LoadSingleCutTmp2.Cycle = Batchpara.DCCut;

    			LoadSingleCutTmp2.QZ = int(Table_DCLineSingleLockList.getFloatField(12)/2);

    			//考虑带至行文件名参数
                stringstream fileNameCalculate("");
                fileNameCalculate << ".\\bpa_temp\\swi_multi_calculate\\temp_" << i + AcAndDC + 1 << ".swi";

    			//将这两个结构体传递给文件并且指定计算的文件名
                bpaSwi.SwiWriteBackToMulti(
                    fileNameCalculate.str(),
                    11,
                    LSStartTmp,
                    LSEndTmp,
                    FLTmp,
                    LDSingleBreakTmp,
                    LoadSingleCutTmp1,
                    LoadSingleCutTmp2,
                    LDDoubleBreakTmp1,
                    LDDoubleBreakTmp2,
                    LoadDoubleCutTmp1,
                    LoadDoubleCutTmp2,
                    LoadDoubleCutTmp3,
                    LoadDoubleCutTmp4);
                ExecuteSwi(fileNameCalculate.str(), baseFileName);

    		}
    		break;
    	}
    case 12:		//直流双极
    	{	
    		double DCLineStartTime = 10;			//用户指参数
    		double DCLoadCutTime = 15;				//用户指定参数
    		//Fault_DtoD1 LDDoubleBreakTmp1,LDDoubleBreakTmp2;					//直流故障
    		//   GenTrip_LoadShed LoadDoubleCutTmp1,LoadDoubleCutTmp2,LoadDoubleCutTmp3,LoadDoubleCutTmp4;			//切机、切负荷
    		for (int i =0;i<DCDoubleNum;i++)
    		{
    			if (ToExecuteSwi::GetBreakCycle())
    			{
    				break;
    			}
    			//直流线路第一极_模拟直流故障
    			LDDoubleBreakTmp1.FaultFlg = "LS";
    			SwiBusName1 = Table_DCLineDoubleLockList.getStringField(2);
    			SwiBusName2 = Table_DCLineDoubleLockList.getStringField(4);
    			boost::replace_all(SwiBusName1,"$","'");
    			boost::replace_all(SwiBusName1,"$","'");
    			LDDoubleBreakTmp1.Bus_A = SwiBusName1;
    			LDDoubleBreakTmp1.BaseVol_A = Table_DCLineDoubleLockList.getFloatField(3);
    			LDDoubleBreakTmp1.Bus_B =SwiBusName2;
    			LDDoubleBreakTmp1.BaseVol_B = Table_DCLineDoubleLockList.getFloatField(5);
    			LDDoubleBreakTmp1.Mde = 5;
    			LDDoubleBreakTmp1.FaultStyle_D = 4;
    			LDDoubleBreakTmp1.Cycle = DCLineStartTime;
    			//直流线路第一极_模拟切负荷
    			LoadDoubleCutTmp1.FaultFlg = "LS";
    			SwiBusName1 = Table_DCLineDoubleLockList.getStringField(6);
    			SwiBusName2 = Table_DCLineDoubleLockList.getStringField(9);
    			boost::replace_all(SwiBusName1,"$","'");
    			boost::replace_all(SwiBusName1,"$","'");
    			//直流线路第一极_补偿1
    			LoadDoubleCutTmp1.BusName =SwiBusName1;
    			LoadDoubleCutTmp1.BusVol = Table_DCLineDoubleLockList.getFloatField(7);
    			LoadDoubleCutTmp1.Mde = 4;
    			LoadDoubleCutTmp1.Cycle = DCLoadCutTime;
    			LoadDoubleCutTmp1.QZ = (Table_DCLineDoubleLockList.getFloatField(8));
    			//直流线路第一极_补偿2
    			LoadDoubleCutTmp2.FaultFlg = "LS";
    			LoadDoubleCutTmp2.BusName =SwiBusName2;
    			LoadDoubleCutTmp2.BusVol = Table_DCLineDoubleLockList.getFloatField(10);
    			LoadDoubleCutTmp2.Mde = 4;
    			LoadDoubleCutTmp2.Cycle = DCLoadCutTime;
    			LoadDoubleCutTmp2.QZ = (Table_DCLineDoubleLockList.getFloatField(11));

    			//直流线路第二极_模拟直流故障
    			LDDoubleBreakTmp2.FaultFlg ="LS";
    			SwiBusName1 = Table_DCLineDoubleLockList.getStringField(12);
    			SwiBusName2 = Table_DCLineDoubleLockList.getStringField(14);
    			boost::replace_all(SwiBusName1,"$","'");
    			boost::replace_all(SwiBusName1,"$","'");
    			LDDoubleBreakTmp2.Bus_A = SwiBusName1;
    			LDDoubleBreakTmp2.BaseVol_A = Table_DCLineDoubleLockList.getFloatField(13);
    			LDDoubleBreakTmp2.Bus_B =SwiBusName2;
    			LDDoubleBreakTmp2.BaseVol_B = Table_DCLineDoubleLockList.getFloatField(15);
    			LDDoubleBreakTmp2.Mde = 5;
    			LDDoubleBreakTmp2.FaultStyle_D = 4;
    			LDDoubleBreakTmp2.Cycle = DCLineStartTime;
    			//直流线路第二极模拟切负荷
    			SwiBusName1 = Table_DCLineDoubleLockList.getStringField(16);
    			SwiBusName2 = Table_DCLineDoubleLockList.getStringField(19);
    			boost::replace_all(SwiBusName1,"$","'");
    			boost::replace_all(SwiBusName1,"$","'");
    			//直流线路第二极补偿1
    			LoadDoubleCutTmp3.FaultFlg = "LS";
    			LoadDoubleCutTmp3.BusName =SwiBusName1;
    			LoadDoubleCutTmp3.BusVol = Table_DCLineDoubleLockList.getFloatField(17);
    			LoadDoubleCutTmp3.Mde = 4;
    			LoadDoubleCutTmp3.Cycle = DCLoadCutTime;
    			LoadDoubleCutTmp3.QZ = (Table_DCLineDoubleLockList.getFloatField(18));
    			//直流线路第二极补偿2
    			LoadDoubleCutTmp4.FaultFlg ="LS";
    			LoadDoubleCutTmp4.BusName =SwiBusName2;
    			LoadDoubleCutTmp4.BusVol = Table_DCLineDoubleLockList.getFloatField(20);
    			LoadDoubleCutTmp4.Mde = 4;
    			LoadDoubleCutTmp4.Cycle = DCLoadCutTime;
    			LoadDoubleCutTmp4.QZ = (Table_DCLineDoubleLockList.getFloatField(21));

    			//考虑带至行文件名参数
                stringstream fileNameCalculate("");
                fileNameCalculate << ".\\bpa_temp\\swi_multi_calculate\\temp_" << i + AcAndDC + 1 << ".swi";

    			//将这两个结构体传递给文件并且指定计算的文件名
                bpaSwi.SwiWriteBackToMulti(
                    fileNameCalculate.str(),
                    12,
                    LSStartTmp,
                    LSEndTmp,
                    FLTmp,
                    LDSingleBreakTmp,
                    LoadSingleCutTmp1,
                    LoadSingleCutTmp2,
    				LDDoubleBreakTmp1,
                    LDDoubleBreakTmp2,
                    LoadDoubleCutTmp1,
                    LoadDoubleCutTmp2,
                    LoadDoubleCutTmp3,
                    LoadDoubleCutTmp4);
                ExecuteSwi(fileNameCalculate.str(), baseFileName);

    		}
    		break;
    	}
    default:
    	break;
    }

    db.close();

    bpaSwi.EraseSwidata();

    return true;
}

int SwiCalculate::CallSwnt(std::string filename, std::string basename)
{
    // TODO:
    string swntexe = ".\\bpa_temp\\swi_multi_calculate\\swnt.exe";
    std::string command = swntexe + " " + basename + " " + filename;
    Process process(command);
    int exit_status = process.get_exit_status();

    return exit_status;
}
